using System;
using UnityEngine;

public class TimeStampUtils
{
	public static double DateTimeToTimestamp(DateTime dateTime)
	{
    	return (dateTime - new DateTime(1970, 1, 1)).TotalSeconds;
	}
	
	public static DateTime TimeStampToDateTime( double timeStamp )
	{
	    DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0);
	    dtDateTime = dtDateTime.AddSeconds( timeStamp );
	    return dtDateTime;
	}
	
	public static int GetTimeStamp()
	{
	    return Convert.ToInt32(DateTimeToTimestamp(DateTime.Now));
	}
	
	public static string GetSpan(double timeStamp){
	    DateTime oldTime = TimeStampToDateTime(timeStamp);
		TimeSpan span = DateTime.Now - oldTime;
		
		int nbMinutes = Mathf.RoundToInt((float)span.TotalMinutes);
		int nbSecondes = Mathf.RoundToInt((float)span.TotalSeconds);
		
		if(nbSecondes >= 60){
			return nbMinutes+" minutes";	
		}else{
			return nbSecondes+" secondes";
		}
		
	}
}

